import Vue from "vue";
export default {
	namespaced: true, // 命名空间必须写
	state: {
		is_individualization: true,
		productList: [],
	},
	getters: {
		getState(state) {
			return state;
		}
	},
	// 唯一修改state值的方法 
	// commit
	mutations: {
		setIsindividualization(state, val) {
			state.is_individualization = val
			Vue.prototype.$setCache('is_individualization', val)
		},
		setProductList(state, val) {
			state.productList = val
		}
	},
	// 异步的操作
	actions: {
		getRecommendList(context) {
			Vue.prototype.$get("product/recommendList", {
				page: 1,
				pageSize: 30
			}).then(res => {
				context.commit('setProductList', res.data)
				const is_individualization = Vue.prototype.$getCache('is_individualization') || true
				context.commit('setIsindividualization', is_individualization)
			}).catch(ex => {
				Vue.prototype.$errorToast(ex);
			})
		},
	}
}